home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 May / maximum-cd-2009-05.iso / DiscContents / Firefox Setup 3.0.6.exe / nonlocalized / chrome / browser.jar / content / browser / preferences / applications.js < prev    next >
Encoding:
JavaScript  |  2008-10-23  |  67.8 KB  |  1,847 lines

  1. /*
  2. //@line 44 "/e/fx19rel/WINNT_5.2_Depend/mozilla/browser/components/preferences/applications.js"
  3.  */
  4.  
  5. //****************************************************************************//
  6. // Constants & Enumeration Values
  7.  
  8. /*
  9. //@line 51 "/e/fx19rel/WINNT_5.2_Depend/mozilla/browser/components/preferences/applications.js"
  10. */
  11. var Cc = Components.classes;
  12. var Ci = Components.interfaces;
  13. var Cr = Components.results;
  14. /*
  15. //@line 57 "/e/fx19rel/WINNT_5.2_Depend/mozilla/browser/components/preferences/applications.js"
  16. */
  17.  
  18. const TYPE_MAYBE_FEED = "application/vnd.mozilla.maybe.feed";
  19. const TYPE_MAYBE_VIDEO_FEED = "application/vnd.mozilla.maybe.video.feed";
  20. const TYPE_MAYBE_AUDIO_FEED = "application/vnd.mozilla.maybe.audio.feed";
  21.  
  22. const PREF_DISABLED_PLUGIN_TYPES = "plugin.disable_full_page_plugin_for_types";
  23.  
  24. // Preferences that affect which entries to show in the list.
  25. const PREF_SHOW_PLUGINS_IN_LIST = "browser.download.show_plugins_in_list";
  26. const PREF_HIDE_PLUGINS_WITHOUT_EXTENSIONS =
  27.   "browser.download.hide_plugins_without_extensions";
  28.  
  29. /*
  30.  * Preferences where we store handling information about the feed type.
  31.  *
  32.  * browser.feeds.handler
  33.  * - "bookmarks", "reader" (clarified further using the .default preference),
  34.  *   or "ask" -- indicates the default handler being used to process feeds;
  35.  *   "bookmarks" is obsolete; to specify that the handler is bookmarks,
  36.  *   set browser.feeds.handler.default to "bookmarks";
  37.  *
  38.  * browser.feeds.handler.default
  39.  * - "bookmarks", "client" or "web" -- indicates the chosen feed reader used
  40.  *   to display feeds, either transiently (i.e., when the "use as default"
  41.  *   checkbox is unchecked, corresponds to when browser.feeds.handler=="ask")
  42.  *   or more permanently (i.e., the item displayed in the dropdown in Feeds
  43.  *   preferences)
  44.  *
  45.  * browser.feeds.handler.webservice
  46.  * - the URL of the currently selected web service used to read feeds
  47.  *
  48.  * browser.feeds.handlers.application
  49.  * - nsILocalFile, stores the current client-side feed reading app if one has
  50.  *   been chosen
  51.  */
  52. const PREF_FEED_SELECTED_APP    = "browser.feeds.handlers.application";
  53. const PREF_FEED_SELECTED_WEB    = "browser.feeds.handlers.webservice";
  54. const PREF_FEED_SELECTED_ACTION = "browser.feeds.handler";
  55. const PREF_FEED_SELECTED_READER = "browser.feeds.handler.default";
  56.  
  57. const PREF_VIDEO_FEED_SELECTED_APP    = "browser.videoFeeds.handlers.application";
  58. const PREF_VIDEO_FEED_SELECTED_WEB    = "browser.videoFeeds.handlers.webservice";
  59. const PREF_VIDEO_FEED_SELECTED_ACTION = "browser.videoFeeds.handler";
  60. const PREF_VIDEO_FEED_SELECTED_READER = "browser.videoFeeds.handler.default";
  61.  
  62. const PREF_AUDIO_FEED_SELECTED_APP    = "browser.audioFeeds.handlers.application";
  63. const PREF_AUDIO_FEED_SELECTED_WEB    = "browser.audioFeeds.handlers.webservice";
  64. const PREF_AUDIO_FEED_SELECTED_ACTION = "browser.audioFeeds.handler";
  65. const PREF_AUDIO_FEED_SELECTED_READER = "browser.audioFeeds.handler.default";
  66.  
  67. // The nsHandlerInfoAction enumeration values in nsIHandlerInfo identify
  68. // the actions the application can take with content of various types.
  69. // But since nsIHandlerInfo doesn't support plugins, there's no value
  70. // identifying the "use plugin" action, so we use this constant instead.
  71. const kActionUsePlugin = 5;
  72.  
  73. const ICON_URL_APP      = "chrome://browser/skin/preferences/application.png";
  74.  
  75. // For CSS. Can be one of "ask", "save", "plugin" or "feed". If absent, the icon URL
  76. // was set by us to a custom handler icon and CSS should not try to override it.
  77. const APP_ICON_ATTR_NAME = "appHandlerIcon";
  78.  
  79. //****************************************************************************//
  80. // Utilities
  81.  
  82. function getDisplayNameForFile(aFile) {
  83. /*
  84. //@line 126 "/e/fx19rel/WINNT_5.2_Depend/mozilla/browser/components/preferences/applications.js"
  85. */
  86.   if (aFile instanceof Ci.nsILocalFileWin) {
  87.     try {
  88.       return aFile.getVersionInfoField("FileDescription"); 
  89.     }
  90.     catch(ex) {
  91.       // fall through to the file name
  92.     }
  93.   }
  94. /*
  95. //@line 149 "/e/fx19rel/WINNT_5.2_Depend/mozilla/browser/components/preferences/applications.js"
  96. */
  97.  
  98.   return Cc["@mozilla.org/network/io-service;1"].
  99.          getService(Ci.nsIIOService).
  100.          newFileURI(aFile).
  101.          QueryInterface(Ci.nsIURL).
  102.          fileName;
  103. }
  104.  
  105. function getLocalHandlerApp(aFile) {
  106.   var localHandlerApp = Cc["@mozilla.org/uriloader/local-handler-app;1"].
  107.                         createInstance(Ci.nsILocalHandlerApp);
  108.   localHandlerApp.name = getDisplayNameForFile(aFile);
  109.   localHandlerApp.executable = aFile;
  110.  
  111.   return localHandlerApp;
  112. }
  113.  
  114. /**
  115.  * An enumeration of items in a JS array.
  116.  *
  117.  * FIXME: use ArrayConverter once it lands (bug 380839).
  118.  * 
  119.  * @constructor
  120.  */
  121. function ArrayEnumerator(aItems) {
  122.   this._index = 0;
  123.   this._contents = aItems;
  124. }
  125.  
  126. ArrayEnumerator.prototype = {
  127.   _index: 0,
  128.  
  129.   hasMoreElements: function() {
  130.     return this._index < this._contents.length;
  131.   },
  132.  
  133.   getNext: function() {
  134.     return this._contents[this._index++];
  135.   }
  136. };
  137.  
  138. function isFeedType(t) {
  139.   return t == TYPE_MAYBE_FEED || t == TYPE_MAYBE_VIDEO_FEED || t == TYPE_MAYBE_AUDIO_FEED;
  140. }
  141.  
  142. //****************************************************************************//
  143. // HandlerInfoWrapper
  144.  
  145. /**
  146.  * This object wraps nsIHandlerInfo with some additional functionality
  147.  * the Applications prefpane needs to display and allow modification of
  148.  * the list of handled types.
  149.  * 
  150.  * We create an instance of this wrapper for each entry we might display
  151.  * in the prefpane, and we compose the instances from various sources,
  152.  * including navigator.plugins and the handler service.
  153.  *
  154.  * We don't implement all the original nsIHandlerInfo functionality,
  155.  * just the stuff that the prefpane needs.
  156.  * 
  157.  * In theory, all of the custom functionality in this wrapper should get
  158.  * pushed down into nsIHandlerInfo eventually.
  159.  */
  160. function HandlerInfoWrapper(aType, aHandlerInfo) {
  161.   this._type = aType;
  162.   this.wrappedHandlerInfo = aHandlerInfo;
  163. }
  164.  
  165. HandlerInfoWrapper.prototype = {
  166.   // The wrapped nsIHandlerInfo object.  In general, this object is private,
  167.   // but there are a couple cases where callers access it directly for things
  168.   // we haven't (yet?) implemented, so we make it a public property.
  169.   wrappedHandlerInfo: null,
  170.  
  171.  
  172.   //**************************************************************************//
  173.   // Convenience Utils
  174.  
  175.   _handlerSvc: Cc["@mozilla.org/uriloader/handler-service;1"].
  176.                getService(Ci.nsIHandlerService),
  177.  
  178.   // Retrieve this as nsIPrefBranch and then immediately QI to nsIPrefBranch2
  179.   // so both interfaces are available to callers.
  180.   _prefSvc: Cc["@mozilla.org/preferences-service;1"].
  181.             getService(Ci.nsIPrefBranch).
  182.             QueryInterface(Ci.nsIPrefBranch2),
  183.  
  184.   _categoryMgr: Cc["@mozilla.org/categorymanager;1"].
  185.                 getService(Ci.nsICategoryManager),
  186.  
  187.   element: function(aID) {
  188.     return document.getElementById(aID);
  189.   },
  190.  
  191.  
  192.   //**************************************************************************//
  193.   // nsIHandlerInfo
  194.  
  195.   // The MIME type or protocol scheme.
  196.   _type: null,
  197.   get type() {
  198.     return this._type;
  199.   },
  200.  
  201.   get description() {
  202.     if (this.wrappedHandlerInfo.description)
  203.       return this.wrappedHandlerInfo.description;
  204.  
  205.     if (this.primaryExtension) {
  206.       var extension = this.primaryExtension.toUpperCase();
  207.       return this.element("bundlePreferences").getFormattedString("fileEnding",
  208.                                                                   [extension]);
  209.     }
  210.  
  211.     return this.type;
  212.   },
  213.  
  214.   get preferredApplicationHandler() {
  215.     return this.wrappedHandlerInfo.preferredApplicationHandler;
  216.   },
  217.  
  218.   set preferredApplicationHandler(aNewValue) {
  219.     this.wrappedHandlerInfo.preferredApplicationHandler = aNewValue;
  220.  
  221.     // Make sure the preferred handler is in the set of possible handlers.
  222.     if (aNewValue)
  223.       this.addPossibleApplicationHandler(aNewValue)
  224.   },
  225.  
  226.   get possibleApplicationHandlers() {
  227.     return this.wrappedHandlerInfo.possibleApplicationHandlers;
  228.   },
  229.  
  230.   addPossibleApplicationHandler: function(aNewHandler) {
  231.     var possibleApps = this.possibleApplicationHandlers.enumerate();
  232.     while (possibleApps.hasMoreElements()) {
  233.       if (possibleApps.getNext().equals(aNewHandler))
  234.         return;
  235.     }
  236.     this.possibleApplicationHandlers.appendElement(aNewHandler, false);
  237.   },
  238.  
  239.   removePossibleApplicationHandler: function(aHandler) {
  240.     var defaultApp = this.preferredApplicationHandler;
  241.     if (defaultApp && aHandler.equals(defaultApp)) {
  242.       // If the app we remove was the default app, we must make sure
  243.       // it won't be used anymore
  244.       this.alwaysAskBeforeHandling = true;
  245.       this.preferredApplicationHandler = null;
  246.     }
  247.  
  248.     var handlers = this.possibleApplicationHandlers;
  249.     for (var i = 0; i < handlers.length; ++i) {
  250.       var handler = handlers.queryElementAt(i, Ci.nsIHandlerApp);
  251.       if (handler.equals(aHandler)) {
  252.         handlers.removeElementAt(i);
  253.         break;
  254.       }
  255.     }
  256.   },
  257.  
  258.   get hasDefaultHandler() {
  259.     return this.wrappedHandlerInfo.hasDefaultHandler;
  260.   },
  261.  
  262.   get defaultDescription() {
  263.     return this.wrappedHandlerInfo.defaultDescription;
  264.   },
  265.  
  266.   // What to do with content of this type.
  267.   get preferredAction() {
  268.     // If we have an enabled plugin, then the action is to use that plugin.
  269.     if (this.plugin && !this.isDisabledPluginType)
  270.       return kActionUsePlugin;
  271.  
  272.     // If the action is to use a helper app, but we don't have a preferred
  273.     // handler app, then switch to using the system default, if any; otherwise
  274.     // fall back to saving to disk, which is the default action in nsMIMEInfo.
  275.     // Note: "save to disk" is an invalid value for protocol info objects,
  276.     // but the alwaysAskBeforeHandling getter will detect that situation
  277.     // and always return true in that case to override this invalid value.
  278.     if (this.wrappedHandlerInfo.preferredAction == Ci.nsIHandlerInfo.useHelperApp &&
  279.         !gApplicationsPane.isValidHandlerApp(this.preferredApplicationHandler)) {
  280.       if (this.wrappedHandlerInfo.hasDefaultHandler)
  281.         return Ci.nsIHandlerInfo.useSystemDefault;
  282.       else
  283.         return Ci.nsIHandlerInfo.saveToDisk;
  284.     }
  285.  
  286.     return this.wrappedHandlerInfo.preferredAction;
  287.   },
  288.  
  289.   set preferredAction(aNewValue) {
  290.     // We don't modify the preferred action if the new action is to use a plugin
  291.     // because handler info objects don't understand our custom "use plugin"
  292.     // value.  Also, leaving it untouched means that we can automatically revert
  293.     // to the old setting if the user ever removes the plugin.
  294.  
  295.     if (aNewValue != kActionUsePlugin)
  296.       this.wrappedHandlerInfo.preferredAction = aNewValue;
  297.   },
  298.  
  299.   get alwaysAskBeforeHandling() {
  300.     // If this type is handled only by a plugin, we can't trust the value
  301.     // in the handler info object, since it'll be a default based on the absence
  302.     // of any user configuration, and the default in that case is to always ask,
  303.     // even though we never ask for content handled by a plugin, so special case
  304.     // plugin-handled types by returning false here.
  305.     if (this.plugin && this.handledOnlyByPlugin)
  306.       return false;
  307.  
  308.     // If this is a protocol type and the preferred action is "save to disk",
  309.     // which is invalid for such types, then return true here to override that
  310.     // action.  This could happen when the preferred action is to use a helper
  311.     // app, but the preferredApplicationHandler is invalid, and there isn't
  312.     // a default handler, so the preferredAction getter returns save to disk
  313.     // instead.
  314.     if (!(this.wrappedHandlerInfo instanceof Ci.nsIMIMEInfo) &&
  315.         this.preferredAction == Ci.nsIHandlerInfo.saveToDisk)
  316.       return true;
  317.  
  318.     return this.wrappedHandlerInfo.alwaysAskBeforeHandling;
  319.   },
  320.  
  321.   set alwaysAskBeforeHandling(aNewValue) {
  322.     this.wrappedHandlerInfo.alwaysAskBeforeHandling = aNewValue;
  323.   },
  324.  
  325.  
  326.   //**************************************************************************//
  327.   // nsIMIMEInfo
  328.  
  329.   // The primary file extension associated with this type, if any.
  330.   //
  331.   // XXX Plugin objects contain an array of MimeType objects with "suffixes"
  332.   // properties; if this object has an associated plugin, shouldn't we check
  333.   // those properties for an extension?
  334.   get primaryExtension() {
  335.     try {
  336.       if (this.wrappedHandlerInfo instanceof Ci.nsIMIMEInfo &&
  337.           this.wrappedHandlerInfo.primaryExtension)
  338.         return this.wrappedHandlerInfo.primaryExtension
  339.     } catch(ex) {}
  340.  
  341.     return null;
  342.   },
  343.  
  344.  
  345.   //**************************************************************************//
  346.   // Plugin Handling
  347.  
  348.   // A plugin that can handle this type, if any.
  349.   //
  350.   // Note: just because we have one doesn't mean it *will* handle the type.
  351.   // That depends on whether or not the type is in the list of types for which
  352.   // plugin handling is disabled.
  353.   plugin: null,
  354.  
  355.   // Whether or not this type is only handled by a plugin or is also handled
  356.   // by some user-configured action as specified in the handler info object.
  357.   //
  358.   // Note: we can't just check if there's a handler info object for this type,
  359.   // because OS and user configuration is mixed up in the handler info object,
  360.   // so we always need to retrieve it for the OS info and can't tell whether
  361.   // it represents only OS-default information or user-configured information.
  362.   //
  363.   // FIXME: once handler info records are broken up into OS-provided records
  364.   // and user-configured records, stop using this boolean flag and simply
  365.   // check for the presence of a user-configured record to determine whether
  366.   // or not this type is only handled by a plugin.  Filed as bug 395142.
  367.   handledOnlyByPlugin: undefined,
  368.  
  369.   get isDisabledPluginType() {
  370.     return this._getDisabledPluginTypes().indexOf(this.type) != -1;
  371.   },
  372.  
  373.   _getDisabledPluginTypes: function() {
  374.     var types = "";
  375.  
  376.     if (this._prefSvc.prefHasUserValue(PREF_DISABLED_PLUGIN_TYPES))
  377.       types = this._prefSvc.getCharPref(PREF_DISABLED_PLUGIN_TYPES);
  378.  
  379.     // Only split if the string isn't empty so we don't end up with an array
  380.     // containing a single empty string.
  381.     if (types != "")
  382.       return types.split(",");
  383.  
  384.     return [];
  385.   },
  386.  
  387.   disablePluginType: function() {
  388.     var disabledPluginTypes = this._getDisabledPluginTypes();
  389.  
  390.     if (disabledPluginTypes.indexOf(this.type) == -1)
  391.       disabledPluginTypes.push(this.type);
  392.  
  393.     this._prefSvc.setCharPref(PREF_DISABLED_PLUGIN_TYPES,
  394.                               disabledPluginTypes.join(","));
  395.  
  396.     // Update the category manager so existing browser windows update.
  397.     this._categoryMgr.deleteCategoryEntry("Gecko-Content-Viewers",
  398.                                           this.type,
  399.                                           false);
  400.   },
  401.  
  402.   enablePluginType: function() {
  403.     var disabledPluginTypes = this._getDisabledPluginTypes();
  404.  
  405.     var type = this.type;
  406.     disabledPluginTypes = disabledPluginTypes.filter(function(v) v != type);
  407.  
  408.     this._prefSvc.setCharPref(PREF_DISABLED_PLUGIN_TYPES,
  409.                               disabledPluginTypes.join(","));
  410.  
  411.     // Update the category manager so existing browser windows update.
  412.     this._categoryMgr.
  413.       addCategoryEntry("Gecko-Content-Viewers",
  414.                        this.type,
  415.                        "@mozilla.org/content/plugin/document-loader-factory;1",
  416.                        false,
  417.                        true);
  418.   },
  419.  
  420.  
  421.   //**************************************************************************//
  422.   // Storage
  423.  
  424.   store: function() {
  425.     this._handlerSvc.store(this.wrappedHandlerInfo);
  426.   },
  427.  
  428.  
  429.   //**************************************************************************//
  430.   // Icons
  431.  
  432.   get smallIcon() {
  433.     return this._getIcon(16);
  434.   },
  435.  
  436.   get largeIcon() {
  437.     return this._getIcon(32);
  438.   },
  439.  
  440.   _getIcon: function(aSize) {
  441.     if (this.primaryExtension)
  442.       return "moz-icon://goat." + this.primaryExtension + "?size=" + aSize;
  443.  
  444.     if (this.wrappedHandlerInfo instanceof Ci.nsIMIMEInfo)
  445.       return "moz-icon://goat?size=" + aSize + "&contentType=" + this.type;
  446.  
  447.     // FIXME: consider returning some generic icon when we can't get a URL for
  448.     // one (for example in the case of protocol schemes).  Filed as bug 395141.
  449.     return null;
  450.   }
  451.  
  452. };
  453.  
  454.  
  455. //****************************************************************************//
  456. // Feed Handler Info
  457.  
  458. /**
  459.  * This object implements nsIHandlerInfo for the feed types.  It's a separate
  460.  * object because we currently store handling information for the feed type
  461.  * in a set of preferences rather than the nsIHandlerService-managed datastore.
  462.  * 
  463.  * This object inherits from HandlerInfoWrapper in order to get functionality
  464.  * that isn't special to the feed type.
  465.  * 
  466.  * XXX Should we inherit from HandlerInfoWrapper?  After all, we override
  467.  * most of that wrapper's properties and methods, and we have to dance around
  468.  * the fact that the wrapper expects to have a wrappedHandlerInfo, which we
  469.  * don't provide.
  470.  */
  471.  
  472. function FeedHandlerInfo(aMIMEType) {
  473.   HandlerInfoWrapper.call(this, aMIMEType, null);
  474. }
  475.  
  476. FeedHandlerInfo.prototype = {
  477.   __proto__: HandlerInfoWrapper.prototype,
  478.  
  479.   //**************************************************************************//
  480.   // Convenience Utils
  481.  
  482.   _converterSvc:
  483.     Cc["@mozilla.org/embeddor.implemented/web-content-handler-registrar;1"].
  484.     getService(Ci.nsIWebContentConverterService),
  485.  
  486.   _shellSvc:
  487. //@line 541 "/e/fx19rel/WINNT_5.2_Depend/mozilla/browser/components/preferences/applications.js"
  488.     getShellService(),
  489. //@line 545 "/e/fx19rel/WINNT_5.2_Depend/mozilla/browser/components/preferences/applications.js"
  490.  
  491.  
  492.   //**************************************************************************//
  493.   // nsIHandlerInfo
  494.  
  495.   get description() {
  496.     return this.element("bundlePreferences").getString(this._appPrefLabel);
  497.   },
  498.  
  499.   get preferredApplicationHandler() {
  500.     switch (this.element(this._prefSelectedReader).value) {
  501.       case "client":
  502.         var file = this.element(this._prefSelectedApp).value;
  503.         if (file)
  504.           return getLocalHandlerApp(file);
  505.  
  506.         return null;
  507.  
  508.       case "web":
  509.         var uri = this.element(this._prefSelectedWeb).value;
  510.         if (!uri)
  511.           return null;
  512.         return this._converterSvc.getWebContentHandlerByURI(this.type, uri);
  513.  
  514.       case "bookmarks":
  515.       default:
  516.         // When the pref is set to bookmarks, we handle feeds internally,
  517.         // we don't forward them to a local or web handler app, so there is
  518.         // no preferred handler.
  519.         return null;
  520.     }
  521.   },
  522.  
  523.   set preferredApplicationHandler(aNewValue) {
  524.     if (aNewValue instanceof Ci.nsILocalHandlerApp) {
  525.       this.element(this._prefSelectedApp).value = aNewValue.executable;
  526.       this.element(this._prefSelectedReader).value = "client";
  527.     }
  528.     else if (aNewValue instanceof Ci.nsIWebContentHandlerInfo) {
  529.       this.element(this._prefSelectedWeb).value = aNewValue.uri;
  530.       this.element(this._prefSelectedReader).value = "web";
  531.       // Make the web handler be the new "auto handler" for feeds.
  532.       // Note: we don't have to unregister the auto handler when the user picks
  533.       // a non-web handler (local app, Live Bookmarks, etc.) because the service
  534.       // only uses the "auto handler" when the selected reader is a web handler.
  535.       // We also don't have to unregister it when the user turns on "always ask"
  536.       // (i.e. preview in browser), since that also overrides the auto handler.
  537.       this._converterSvc.setAutoHandler(this.type, aNewValue);
  538.     }
  539.   },
  540.  
  541.   _possibleApplicationHandlers: null,
  542.  
  543.   get possibleApplicationHandlers() {
  544.     if (this._possibleApplicationHandlers)
  545.       return this._possibleApplicationHandlers;
  546.  
  547.     // A minimal implementation of nsIMutableArray.  It only supports the two
  548.     // methods its callers invoke, namely appendElement and nsIArray::enumerate.
  549.     this._possibleApplicationHandlers = {
  550.       _inner: [],
  551.       _removed: [],
  552.  
  553.       QueryInterface: function(aIID) {
  554.         if (aIID.equals(Ci.nsIMutableArray) ||
  555.             aIID.equals(Ci.nsIArray) ||
  556.             aIID.equals(Ci.nsISupports))
  557.           return this;
  558.  
  559.         throw Cr.NS_ERROR_NO_INTERFACE;
  560.       },
  561.  
  562.       get length() {
  563.         return this._inner.length;
  564.       },
  565.  
  566.       enumerate: function() {
  567.         return new ArrayEnumerator(this._inner);
  568.       },
  569.  
  570.       appendElement: function(aHandlerApp, aWeak) {
  571.         this._inner.push(aHandlerApp);
  572.       },
  573.  
  574.       removeElementAt: function(aIndex) {
  575.         this._removed.push(this._inner[aIndex]);
  576.         this._inner.splice(aIndex, 1);
  577.       },
  578.  
  579.       queryElementAt: function(aIndex, aInterface) {
  580.         return this._inner[aIndex].QueryInterface(aInterface);
  581.       }
  582.     };
  583.  
  584.     // Add the selected local app if it's different from the OS default handler.
  585.     // Unlike for other types, we can store only one local app at a time for the
  586.     // feed type, since we store it in a preference that historically stores
  587.     // only a single path.  But we display all the local apps the user chooses
  588.     // while the prefpane is open, only dropping the list when the user closes
  589.     // the prefpane, for maximum usability and consistency with other types.
  590.     var preferredAppFile = this.element(this._prefSelectedApp).value;
  591.     if (preferredAppFile) {
  592.       let preferredApp = getLocalHandlerApp(preferredAppFile);
  593.       let defaultApp = this._defaultApplicationHandler;
  594.       if (!defaultApp || !defaultApp.equals(preferredApp))
  595.         this._possibleApplicationHandlers.appendElement(preferredApp, false);
  596.     }
  597.  
  598.     // Add the registered web handlers.  There can be any number of these.
  599.     var webHandlers = this._converterSvc.getContentHandlers(this.type, {});
  600.     for each (let webHandler in webHandlers)
  601.       this._possibleApplicationHandlers.appendElement(webHandler, false);
  602.  
  603.     return this._possibleApplicationHandlers;
  604.   },
  605.  
  606.   __defaultApplicationHandler: undefined,
  607.   get _defaultApplicationHandler() {
  608.     if (typeof this.__defaultApplicationHandler != "undefined")
  609.       return this.__defaultApplicationHandler;
  610.  
  611.     var defaultFeedReader = null;
  612. //@line 668 "/e/fx19rel/WINNT_5.2_Depend/mozilla/browser/components/preferences/applications.js"
  613.     try {
  614.       defaultFeedReader = this._shellSvc.defaultFeedReader;
  615.     }
  616.     catch(ex) {
  617.       // no default reader or _shellSvc is null
  618.     }
  619. //@line 675 "/e/fx19rel/WINNT_5.2_Depend/mozilla/browser/components/preferences/applications.js"
  620.  
  621.     if (defaultFeedReader) {
  622.       let handlerApp = Cc["@mozilla.org/uriloader/local-handler-app;1"].
  623.                        createInstance(Ci.nsIHandlerApp);
  624.       handlerApp.name = getDisplayNameForFile(defaultFeedReader);
  625.       handlerApp.QueryInterface(Ci.nsILocalHandlerApp);
  626.       handlerApp.executable = defaultFeedReader;
  627.  
  628.       this.__defaultApplicationHandler = handlerApp;
  629.     }
  630.     else {
  631.       this.__defaultApplicationHandler = null;
  632.     }
  633.  
  634.     return this.__defaultApplicationHandler;
  635.   },
  636.  
  637.   get hasDefaultHandler() {
  638. //@line 694 "/e/fx19rel/WINNT_5.2_Depend/mozilla/browser/components/preferences/applications.js"
  639.     try {
  640.       if (this._shellSvc.defaultFeedReader)
  641.         return true;
  642.     }
  643.     catch(ex) {
  644.       // no default reader or _shellSvc is null
  645.     }
  646. //@line 702 "/e/fx19rel/WINNT_5.2_Depend/mozilla/browser/components/preferences/applications.js"
  647.  
  648.     return false;
  649.   },
  650.  
  651.   get defaultDescription() {
  652.     if (this.hasDefaultHandler)
  653.       return this._defaultApplicationHandler.name;
  654.  
  655.     // Should we instead return null?
  656.     return "";
  657.   },
  658.  
  659.   // What to do with content of this type.
  660.   get preferredAction() {
  661.     switch (this.element(this._prefSelectedAction).value) {
  662.  
  663.       case "bookmarks":
  664.         return Ci.nsIHandlerInfo.handleInternally;
  665.  
  666.       case "reader": {
  667.         let preferredApp = this.preferredApplicationHandler;
  668.         let defaultApp = this._defaultApplicationHandler;
  669.  
  670.         // If we have a valid preferred app, return useSystemDefault if it's
  671.         // the default app; otherwise return useHelperApp.
  672.         if (gApplicationsPane.isValidHandlerApp(preferredApp)) {
  673.           if (defaultApp && defaultApp.equals(preferredApp))
  674.             return Ci.nsIHandlerInfo.useSystemDefault;
  675.  
  676.           return Ci.nsIHandlerInfo.useHelperApp;
  677.         }
  678.  
  679.         // The pref is set to "reader", but we don't have a valid preferred app.
  680.         // What do we do now?  Not sure this is the best option (perhaps we
  681.         // should direct the user to the default app, if any), but for now let's
  682.         // direct the user to live bookmarks.
  683.         return Ci.nsIHandlerInfo.handleInternally;
  684.       }
  685.  
  686.       // If the action is "ask", then alwaysAskBeforeHandling will override
  687.       // the action, so it doesn't matter what we say it is, it just has to be
  688.       // something that doesn't cause the controller to hide the type.
  689.       case "ask":
  690.       default:
  691.         return Ci.nsIHandlerInfo.handleInternally;
  692.     }
  693.   },
  694.  
  695.   set preferredAction(aNewValue) {
  696.     switch (aNewValue) {
  697.  
  698.       case Ci.nsIHandlerInfo.handleInternally:
  699.         this.element(this._prefSelectedReader).value = "bookmarks";
  700.         break;
  701.  
  702.       case Ci.nsIHandlerInfo.useHelperApp:
  703.         this.element(this._prefSelectedAction).value = "reader";
  704.         // The controller has already set preferredApplicationHandler
  705.         // to the new helper app.
  706.         break;
  707.  
  708.       case Ci.nsIHandlerInfo.useSystemDefault:
  709.         this.element(this._prefSelectedAction).value = "reader";
  710.         this.preferredApplicationHandler = this._defaultApplicationHandler;
  711.         break;
  712.     }
  713.   },
  714.  
  715.   get alwaysAskBeforeHandling() {
  716.     return this.element(this._prefSelectedAction).value == "ask";
  717.   },
  718.  
  719.   set alwaysAskBeforeHandling(aNewValue) {
  720.     if (aNewValue == true)
  721.       this.element(this._prefSelectedAction).value = "ask";
  722.     else
  723.       this.element(this._prefSelectedAction).value = "reader";
  724.   },
  725.  
  726.   // Whether or not we are currently storing the action selected by the user.
  727.   // We use this to suppress notification-triggered updates to the list when
  728.   // we make changes that may spawn such updates, specifically when we change
  729.   // the action for the feed type, which results in feed preference updates,
  730.   // which spawn "pref changed" notifications that would otherwise cause us
  731.   // to rebuild the view unnecessarily.
  732.   _storingAction: false,
  733.  
  734.  
  735.   //**************************************************************************//
  736.   // nsIMIMEInfo
  737.  
  738.   get primaryExtension() {
  739.     return "xml";
  740.   },
  741.  
  742.  
  743.   //**************************************************************************//
  744.   // Storage
  745.  
  746.   // Changes to the preferred action and handler take effect immediately
  747.   // (we write them out to the preferences right as they happen),
  748.   // so we when the controller calls store() after modifying the handlers,
  749.   // the only thing we need to store is the removal of possible handlers
  750.   // XXX Should we hold off on making the changes until this method gets called?
  751.   store: function() {
  752.     for each (let app in this._possibleApplicationHandlers._removed) {
  753.       if (app instanceof Ci.nsILocalHandlerApp) {
  754.         let pref = this.element(PREF_FEED_SELECTED_APP);
  755.         var preferredAppFile = pref.value;
  756.         if (preferredAppFile) {
  757.           let preferredApp = getLocalHandlerApp(preferredAppFile);
  758.           if (app.equals(preferredApp))
  759.             pref.reset();
  760.         }
  761.       }
  762.       else {
  763.         app.QueryInterface(Ci.nsIWebContentHandlerInfo);
  764.         this._converterSvc.removeContentHandler(app.contentType, app.uri);
  765.       }
  766.     }
  767.     this._possibleApplicationHandlers._removed = [];
  768.   },
  769.  
  770.  
  771.   //**************************************************************************//
  772.   // Icons
  773.  
  774.   get smallIcon() {
  775.     return this._smallIcon;
  776.   },
  777.  
  778.   get largeIcon() {
  779.     return this._largeIcon;
  780.   }
  781.  
  782. };
  783.  
  784. var feedHandlerInfo = {
  785.   __proto__: new FeedHandlerInfo(TYPE_MAYBE_FEED),
  786.   _prefSelectedApp: PREF_FEED_SELECTED_APP, 
  787.   _prefSelectedWeb: PREF_FEED_SELECTED_WEB, 
  788.   _prefSelectedAction: PREF_FEED_SELECTED_ACTION, 
  789.   _prefSelectedReader: PREF_FEED_SELECTED_READER,
  790.   _smallIcon: "chrome://browser/skin/feeds/feedIcon16.png",
  791.   _largeIcon: "chrome://browser/skin/feeds/feedIcon.png",
  792.   _appPrefLabel: "webFeed"
  793. }
  794.  
  795. var videoFeedHandlerInfo = {
  796.   __proto__: new FeedHandlerInfo(TYPE_MAYBE_VIDEO_FEED),
  797.   _prefSelectedApp: PREF_VIDEO_FEED_SELECTED_APP, 
  798.   _prefSelectedWeb: PREF_VIDEO_FEED_SELECTED_WEB, 
  799.   _prefSelectedAction: PREF_VIDEO_FEED_SELECTED_ACTION, 
  800.   _prefSelectedReader: PREF_VIDEO_FEED_SELECTED_READER,
  801.   _smallIcon: "chrome://browser/skin/feeds/videoFeedIcon16.png",
  802.   _largeIcon: "chrome://browser/skin/feeds/videoFeedIcon.png",
  803.   _appPrefLabel: "videoPodcastFeed"
  804. }
  805.  
  806. var audioFeedHandlerInfo = {
  807.   __proto__: new FeedHandlerInfo(TYPE_MAYBE_AUDIO_FEED),
  808.   _prefSelectedApp: PREF_AUDIO_FEED_SELECTED_APP, 
  809.   _prefSelectedWeb: PREF_AUDIO_FEED_SELECTED_WEB, 
  810.   _prefSelectedAction: PREF_AUDIO_FEED_SELECTED_ACTION, 
  811.   _prefSelectedReader: PREF_AUDIO_FEED_SELECTED_READER,
  812.   _smallIcon: "chrome://browser/skin/feeds/audioFeedIcon16.png",
  813.   _largeIcon: "chrome://browser/skin/feeds/audioFeedIcon.png",
  814.   _appPrefLabel: "audioPodcastFeed"
  815. }
  816.  
  817.  
  818. //****************************************************************************//
  819. // Prefpane Controller
  820.  
  821. var gApplicationsPane = {
  822.   // The set of types the app knows how to handle.  A hash of HandlerInfoWrapper
  823.   // objects, indexed by type.
  824.   _handledTypes: {},
  825.   
  826.   // The list of types we can show, sorted by the sort column/direction.
  827.   // An array of HandlerInfoWrapper objects.  We build this list when we first
  828.   // load the data and then rebuild it when users change a pref that affects
  829.   // what types we can show or change the sort column/direction.
  830.   // Note: this isn't necessarily the list of types we *will* show; if the user
  831.   // provides a filter string, we'll only show the subset of types in this list
  832.   // that match that string.
  833.   _visibleTypes: [],
  834.  
  835.   // A count of the number of times each visible type description appears.
  836.   // We use these counts to determine whether or not to annotate descriptions
  837.   // with their types to distinguish duplicate descriptions from each other.
  838.   // A hash of integer counts, indexed by string description.
  839.   _visibleTypeDescriptionCount: {},
  840.  
  841.  
  842.   //**************************************************************************//
  843.   // Convenience & Performance Shortcuts
  844.  
  845.   // These get defined by init().
  846.   _brandShortName : null,
  847.   _prefsBundle    : null,
  848.   _list           : null,
  849.   _filter         : null,
  850.  
  851.   // Retrieve this as nsIPrefBranch and then immediately QI to nsIPrefBranch2
  852.   // so both interfaces are available to callers.
  853.   _prefSvc      : Cc["@mozilla.org/preferences-service;1"].
  854.                   getService(Ci.nsIPrefBranch).
  855.                   QueryInterface(Ci.nsIPrefBranch2),
  856.  
  857.   _mimeSvc      : Cc["@mozilla.org/mime;1"].
  858.                   getService(Ci.nsIMIMEService),
  859.  
  860.   _helperAppSvc : Cc["@mozilla.org/uriloader/external-helper-app-service;1"].
  861.                   getService(Ci.nsIExternalHelperAppService),
  862.  
  863.   _handlerSvc   : Cc["@mozilla.org/uriloader/handler-service;1"].
  864.                   getService(Ci.nsIHandlerService),
  865.  
  866.   _ioSvc        : Cc["@mozilla.org/network/io-service;1"].
  867.                   getService(Ci.nsIIOService),
  868.  
  869.  
  870.   //**************************************************************************//
  871.   // Initialization & Destruction
  872.  
  873.   init: function() {
  874.     // Initialize shortcuts to some commonly accessed elements & values.
  875.     this._brandShortName =
  876.       document.getElementById("bundleBrand").getString("brandShortName");
  877.     this._prefsBundle = document.getElementById("bundlePreferences");
  878.     this._list = document.getElementById("handlersView");
  879.     this._filter = document.getElementById("filter");
  880.  
  881.     // Observe preferences that influence what we display so we can rebuild
  882.     // the view when they change.
  883.     this._prefSvc.addObserver(PREF_SHOW_PLUGINS_IN_LIST, this, false);
  884.     this._prefSvc.addObserver(PREF_HIDE_PLUGINS_WITHOUT_EXTENSIONS, this, false);
  885.     this._prefSvc.addObserver(PREF_FEED_SELECTED_APP, this, false);
  886.     this._prefSvc.addObserver(PREF_FEED_SELECTED_WEB, this, false);
  887.     this._prefSvc.addObserver(PREF_FEED_SELECTED_ACTION, this, false);
  888.     this._prefSvc.addObserver(PREF_FEED_SELECTED_READER, this, false);
  889.  
  890.     this._prefSvc.addObserver(PREF_VIDEO_FEED_SELECTED_APP, this, false);
  891.     this._prefSvc.addObserver(PREF_VIDEO_FEED_SELECTED_WEB, this, false);
  892.     this._prefSvc.addObserver(PREF_VIDEO_FEED_SELECTED_ACTION, this, false);
  893.     this._prefSvc.addObserver(PREF_VIDEO_FEED_SELECTED_READER, this, false);
  894.  
  895.     this._prefSvc.addObserver(PREF_AUDIO_FEED_SELECTED_APP, this, false);
  896.     this._prefSvc.addObserver(PREF_AUDIO_FEED_SELECTED_WEB, this, false);
  897.     this._prefSvc.addObserver(PREF_AUDIO_FEED_SELECTED_ACTION, this, false);
  898.     this._prefSvc.addObserver(PREF_AUDIO_FEED_SELECTED_READER, this, false);
  899.  
  900.  
  901.     // Listen for window unload so we can remove our preference observers.
  902.     window.addEventListener("unload", this, false);
  903.  
  904.     // Figure out how we should be sorting the list.  We persist sort settings
  905.     // across sessions, so we can't assume the default sort column/direction.
  906.     // XXX should we be using the XUL sort service instead?
  907.     if (document.getElementById("actionColumn").hasAttribute("sortDirection")) {
  908.       this._sortColumn = document.getElementById("actionColumn");
  909.       // The typeColumn element always has a sortDirection attribute,
  910.       // either because it was persisted or because the default value
  911.       // from the xul file was used.  If we are sorting on the other
  912.       // column, we should remove it.
  913.       document.getElementById("typeColumn").removeAttribute("sortDirection");
  914.     }
  915.     else 
  916.       this._sortColumn = document.getElementById("typeColumn");
  917.  
  918.     // Load the data and build the list of handlers.
  919.     // By doing this in a timeout, we let the preferences dialog resize itself
  920.     // to an appropriate size before we add a bunch of items to the list.
  921.     // Otherwise, if there are many items, and the Applications prefpane
  922.     // is the one that gets displayed when the user first opens the dialog,
  923.     // the dialog might stretch too much in an attempt to fit them all in.
  924.     // XXX Shouldn't we perhaps just set a max-height on the richlistbox?
  925.     var _delayedPaneLoad = function(self) {
  926.       self._loadData();
  927.       self._rebuildVisibleTypes();
  928.       self._sortVisibleTypes();
  929.       self._rebuildView();
  930.  
  931.       // Notify observers that the UI is now ready
  932.       Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService).
  933.       notifyObservers(window, "app-handler-pane-loaded", null);
  934.     }
  935.     setTimeout(_delayedPaneLoad, 0, this);
  936.   },
  937.  
  938.   destroy: function() {
  939.     window.removeEventListener("unload", this, false);
  940.     this._prefSvc.removeObserver(PREF_SHOW_PLUGINS_IN_LIST, this);
  941.     this._prefSvc.removeObserver(PREF_HIDE_PLUGINS_WITHOUT_EXTENSIONS, this);
  942.     this._prefSvc.removeObserver(PREF_FEED_SELECTED_APP, this);
  943.     this._prefSvc.removeObserver(PREF_FEED_SELECTED_WEB, this);
  944.     this._prefSvc.removeObserver(PREF_FEED_SELECTED_ACTION, this);
  945.     this._prefSvc.removeObserver(PREF_FEED_SELECTED_READER, this);
  946.  
  947.     this._prefSvc.removeObserver(PREF_VIDEO_FEED_SELECTED_APP, this);
  948.     this._prefSvc.removeObserver(PREF_VIDEO_FEED_SELECTED_WEB, this);
  949.     this._prefSvc.removeObserver(PREF_VIDEO_FEED_SELECTED_ACTION, this);
  950.     this._prefSvc.removeObserver(PREF_VIDEO_FEED_SELECTED_READER, this);
  951.  
  952.     this._prefSvc.removeObserver(PREF_AUDIO_FEED_SELECTED_APP, this);
  953.     this._prefSvc.removeObserver(PREF_AUDIO_FEED_SELECTED_WEB, this);
  954.     this._prefSvc.removeObserver(PREF_AUDIO_FEED_SELECTED_ACTION, this);
  955.     this._prefSvc.removeObserver(PREF_AUDIO_FEED_SELECTED_READER, this);
  956.   },
  957.  
  958.  
  959.   //**************************************************************************//
  960.   // nsISupports
  961.  
  962.   QueryInterface: function(aIID) {
  963.     if (aIID.equals(Ci.nsIObserver) ||
  964.         aIID.equals(Ci.nsIDOMEventListener ||
  965.         aIID.equals(Ci.nsISupports)))
  966.       return this;
  967.  
  968.     throw Cr.NS_ERROR_NO_INTERFACE;
  969.   },
  970.  
  971.  
  972.   //**************************************************************************//
  973.   // nsIObserver
  974.  
  975.   observe: function (aSubject, aTopic, aData) {
  976.     // Rebuild the list when there are changes to preferences that influence
  977.     // whether or not to show certain entries in the list.
  978.     if (aTopic == "nsPref:changed" && !this._storingAction) {
  979.       // These two prefs alter the list of visible types, so we have to rebuild
  980.       // that list when they change.
  981.       if (aData == PREF_SHOW_PLUGINS_IN_LIST ||
  982.           aData == PREF_HIDE_PLUGINS_WITHOUT_EXTENSIONS) {
  983.         this._rebuildVisibleTypes();
  984.         this._sortVisibleTypes();
  985.       }
  986.  
  987.       // All the prefs we observe can affect what we display, so we rebuild
  988.       // the view when any of them changes.
  989.       this._rebuildView();
  990.     }
  991.   },
  992.  
  993.  
  994.   //**************************************************************************//
  995.   // nsIDOMEventListener
  996.  
  997.   handleEvent: function(aEvent) {
  998.     if (aEvent.type == "unload") {
  999.       this.destroy();
  1000.     }
  1001.   },
  1002.  
  1003.  
  1004.   //**************************************************************************//
  1005.   // Composed Model Construction
  1006.  
  1007.   _loadData: function() {
  1008.     this._loadFeedHandler();
  1009.     this._loadPluginHandlers();
  1010.     this._loadApplicationHandlers();
  1011.   },
  1012.  
  1013.   _loadFeedHandler: function() {
  1014.     this._handledTypes[TYPE_MAYBE_FEED] = feedHandlerInfo;
  1015.     feedHandlerInfo.handledOnlyByPlugin = false;
  1016.  
  1017.     this._handledTypes[TYPE_MAYBE_VIDEO_FEED] = videoFeedHandlerInfo;
  1018.     videoFeedHandlerInfo.handledOnlyByPlugin = false;
  1019.  
  1020.     this._handledTypes[TYPE_MAYBE_AUDIO_FEED] = audioFeedHandlerInfo;
  1021.     audioFeedHandlerInfo.handledOnlyByPlugin = false;
  1022.   },
  1023.  
  1024.   /**
  1025.    * Load the set of handlers defined by plugins.
  1026.    *
  1027.    * Note: if there's more than one plugin for a given MIME type, we assume
  1028.    * the last one is the one that the application will use.  That may not be
  1029.    * correct, but it's how we've been doing it for years.
  1030.    *
  1031.    * Perhaps we should instead query navigator.mimeTypes for the set of types
  1032.    * supported by the application and then get the plugin from each MIME type's
  1033.    * enabledPlugin property.  But if there's a plugin for a type, we need
  1034.    * to know about it even if it isn't enabled, since we're going to give
  1035.    * the user an option to enable it.
  1036.    * 
  1037.    * I'll also note that my reading of nsPluginTag::RegisterWithCategoryManager
  1038.    * suggests that enabledPlugin is only determined during registration
  1039.    * and does not get updated when plugin.disable_full_page_plugin_for_types
  1040.    * changes (unless modification of that preference spawns reregistration).
  1041.    * So even if we could use enabledPlugin to get the plugin that would be used,
  1042.    * we'd still need to check the pref ourselves to find out if it's enabled.
  1043.    */
  1044.   _loadPluginHandlers: function() {
  1045.     for (let i = 0; i < navigator.plugins.length; ++i) {
  1046.       let plugin = navigator.plugins[i];
  1047.       for (let j = 0; j < plugin.length; ++j) {
  1048.         let type = plugin[j].type;
  1049.  
  1050.         let handlerInfoWrapper;
  1051.         if (type in this._handledTypes)
  1052.           handlerInfoWrapper = this._handledTypes[type];
  1053.         else {
  1054.           let wrappedHandlerInfo =
  1055.             this._mimeSvc.getFromTypeAndExtension(type, null);
  1056.           handlerInfoWrapper = new HandlerInfoWrapper(type, wrappedHandlerInfo);
  1057.           handlerInfoWrapper.handledOnlyByPlugin = true;
  1058.           this._handledTypes[type] = handlerInfoWrapper;
  1059.         }
  1060.  
  1061.         handlerInfoWrapper.plugin = plugin;
  1062.       }
  1063.     }
  1064.   },
  1065.  
  1066.   /**
  1067.    * Load the set of handlers defined by the application datastore.
  1068.    */
  1069.   _loadApplicationHandlers: function() {
  1070.     var wrappedHandlerInfos = this._handlerSvc.enumerate();
  1071.     while (wrappedHandlerInfos.hasMoreElements()) {
  1072.       let wrappedHandlerInfo =
  1073.         wrappedHandlerInfos.getNext().QueryInterface(Ci.nsIHandlerInfo);
  1074.       let type = wrappedHandlerInfo.type;
  1075.  
  1076.       let handlerInfoWrapper;
  1077.       if (type in this._handledTypes)
  1078.         handlerInfoWrapper = this._handledTypes[type];
  1079.       else {
  1080.         handlerInfoWrapper = new HandlerInfoWrapper(type, wrappedHandlerInfo);
  1081.         this._handledTypes[type] = handlerInfoWrapper;
  1082.       }
  1083.  
  1084.       handlerInfoWrapper.handledOnlyByPlugin = false;
  1085.     }
  1086.   },
  1087.  
  1088.  
  1089.   //**************************************************************************//
  1090.   // View Construction
  1091.  
  1092.   _rebuildVisibleTypes: function() {
  1093.     // Reset the list of visible types and the visible type description counts.
  1094.     this._visibleTypes = [];
  1095.     this._visibleTypeDescriptionCount = {};
  1096.  
  1097.     // Get the preferences that help determine what types to show.
  1098.     var showPlugins = this._prefSvc.getBoolPref(PREF_SHOW_PLUGINS_IN_LIST);
  1099.     var hidePluginsWithoutExtensions =
  1100.       this._prefSvc.getBoolPref(PREF_HIDE_PLUGINS_WITHOUT_EXTENSIONS);
  1101.  
  1102.     for (let type in this._handledTypes) {
  1103.       let handlerInfo = this._handledTypes[type];
  1104.  
  1105.       // Hide plugins without associated extensions if so prefed so we don't
  1106.       // show a whole bunch of obscure types handled by plugins on Mac.
  1107.       // Note: though protocol types don't have extensions, we still show them;
  1108.       // the pref is only meant to be applied to MIME types, since plugins are
  1109.       // only associated with MIME types.
  1110.       // FIXME: should we also check the "suffixes" property of the plugin?
  1111.       // Filed as bug 395135.
  1112.       if (hidePluginsWithoutExtensions && handlerInfo.handledOnlyByPlugin &&
  1113.           handlerInfo.wrappedHandlerInfo instanceof Ci.nsIMIMEInfo &&
  1114.           !handlerInfo.primaryExtension)
  1115.         continue;
  1116.  
  1117.       // Hide types handled only by plugins if so prefed.
  1118.       if (handlerInfo.handledOnlyByPlugin && !showPlugins)
  1119.         continue;
  1120.  
  1121.       // We couldn't find any reason to exclude the type, so include it.
  1122.       this._visibleTypes.push(handlerInfo);
  1123.  
  1124.       if (handlerInfo.description in this._visibleTypeDescriptionCount)
  1125.         this._visibleTypeDescriptionCount[handlerInfo.description]++;
  1126.       else
  1127.         this._visibleTypeDescriptionCount[handlerInfo.description] = 1;
  1128.     }
  1129.   },
  1130.  
  1131.   _rebuildView: function() {
  1132.     // Clear the list of entries.
  1133.     while (this._list.childNodes.length > 1)
  1134.       this._list.removeChild(this._list.lastChild);
  1135.  
  1136.     var visibleTypes = this._visibleTypes;
  1137.  
  1138.     // If the user is filtering the list, then only show matching types.
  1139.     if (this._filter.value)
  1140.       visibleTypes = visibleTypes.filter(this._matchesFilter, this);
  1141.  
  1142.     for each (let visibleType in visibleTypes) {
  1143.       let item = document.createElement("richlistitem");
  1144.       item.setAttribute("type", visibleType.type);
  1145.       item.setAttribute("typeDescription", this._describeType(visibleType));
  1146.       if (visibleType.smallIcon)
  1147.         item.setAttribute("typeIcon", visibleType.smallIcon);
  1148.       item.setAttribute("actionDescription",
  1149.                         this._describePreferredAction(visibleType));
  1150.  
  1151.       if (!this._setIconClassForPreferredAction(visibleType, item)) {
  1152.         item.setAttribute("actionIcon",
  1153.                           this._getIconURLForPreferredAction(visibleType));
  1154.       }
  1155.  
  1156.       this._list.appendChild(item);
  1157.     }
  1158.  
  1159.     this._selectLastSelectedType();
  1160.   },
  1161.  
  1162.   _matchesFilter: function(aType) {
  1163.     var filterValue = this._filter.value.toLowerCase();
  1164.     return this._describeType(aType).toLowerCase().indexOf(filterValue) != -1 ||
  1165.            this._describePreferredAction(aType).toLowerCase().indexOf(filterValue) != -1;
  1166.   },
  1167.  
  1168.   /**
  1169.    * Describe, in a human-readable fashion, the type represented by the given
  1170.    * handler info object.  Normally this is just the description provided by
  1171.    * the info object, but if more than one object presents the same description,
  1172.    * then we annotate the duplicate descriptions with the type itself to help
  1173.    * users distinguish between those types.
  1174.    *
  1175.    * @param aHandlerInfo {nsIHandlerInfo} the type being described
  1176.    * @returns {string} a description of the type
  1177.    */
  1178.   _describeType: function(aHandlerInfo) {
  1179.     if (this._visibleTypeDescriptionCount[aHandlerInfo.description] > 1)
  1180.       return this._prefsBundle.getFormattedString("typeDescriptionWithType",
  1181.                                                   [aHandlerInfo.description,
  1182.                                                    aHandlerInfo.type]);
  1183.  
  1184.     return aHandlerInfo.description;
  1185.   },
  1186.  
  1187.   /**
  1188.    * Describe, in a human-readable fashion, the preferred action to take on
  1189.    * the type represented by the given handler info object.
  1190.    *
  1191.    * XXX Should this be part of the HandlerInfoWrapper interface?  It would
  1192.    * violate the separation of model and view, but it might make more sense
  1193.    * nonetheless (f.e. it would make sortTypes easier).
  1194.    *
  1195.    * @param aHandlerInfo {nsIHandlerInfo} the type whose preferred action
  1196.    *                                      is being described
  1197.    * @returns {string} a description of the action
  1198.    */
  1199.   _describePreferredAction: function(aHandlerInfo) {
  1200.     // alwaysAskBeforeHandling overrides the preferred action, so if that flag
  1201.     // is set, then describe that behavior instead.  For most types, this is
  1202.     // the "alwaysAsk" string, but for the feed type we show something special.
  1203.     if (aHandlerInfo.alwaysAskBeforeHandling) {
  1204.       if (isFeedType(aHandlerInfo.type))
  1205.         return this._prefsBundle.getFormattedString("previewInApp",
  1206.                                                     [this._brandShortName]);
  1207.       else
  1208.         return this._prefsBundle.getString("alwaysAsk");
  1209.     }
  1210.  
  1211.     switch (aHandlerInfo.preferredAction) {
  1212.       case Ci.nsIHandlerInfo.saveToDisk:
  1213.         return this._prefsBundle.getString("saveFile");
  1214.  
  1215.       case Ci.nsIHandlerInfo.useHelperApp:
  1216.         var preferredApp = aHandlerInfo.preferredApplicationHandler;
  1217.         var name;
  1218.         if (preferredApp instanceof Ci.nsILocalHandlerApp)
  1219.           name = getDisplayNameForFile(preferredApp.executable);
  1220.         else
  1221.           name = preferredApp.name;
  1222.         return this._prefsBundle.getFormattedString("useApp", [name]);
  1223.  
  1224.       case Ci.nsIHandlerInfo.handleInternally:
  1225.         // For the feed type, handleInternally means live bookmarks.
  1226.         if (isFeedType(aHandlerInfo.type)) 
  1227.           return this._prefsBundle.getFormattedString("addLiveBookmarksInApp",
  1228.                                                       [this._brandShortName]);
  1229.  
  1230.         // For other types, handleInternally looks like either useHelperApp
  1231.         // or useSystemDefault depending on whether or not there's a preferred
  1232.         // handler app.
  1233.         if (this.isValidHandlerApp(aHandlerInfo.preferredApplicationHandler))
  1234.           return aHandlerInfo.preferredApplicationHandler.name;
  1235.  
  1236.         return aHandlerInfo.defaultDescription;
  1237.  
  1238.         // XXX Why don't we say the app will handle the type internally?
  1239.         // Is it because the app can't actually do that?  But if that's true,
  1240.         // then why would a preferredAction ever get set to this value
  1241.         // in the first place?
  1242.  
  1243.       case Ci.nsIHandlerInfo.useSystemDefault:
  1244.         return this._prefsBundle.getFormattedString("useDefault",
  1245.                                                     [aHandlerInfo.defaultDescription]);
  1246.  
  1247.       case kActionUsePlugin:
  1248.         return this._prefsBundle.getFormattedString("usePluginIn",
  1249.                                                     [aHandlerInfo.plugin.name,
  1250.                                                      this._brandShortName]);
  1251.     }
  1252.   },
  1253.  
  1254.   _selectLastSelectedType: function() {
  1255.     // If the list is disabled by the pref.downloads.disable_button.edit_actions
  1256.     // preference being locked, then don't select the type, as that would cause
  1257.     // it to appear selected, with a different background and an actions menu
  1258.     // that makes it seem like you can choose an action for the type.
  1259.     if (this._list.disabled)
  1260.       return;
  1261.  
  1262.     var lastSelectedType = this._list.getAttribute("lastSelectedType");
  1263.     if (!lastSelectedType)
  1264.       return;
  1265.  
  1266.     var item = this._list.getElementsByAttribute("type", lastSelectedType)[0];
  1267.     if (!item)
  1268.       return;
  1269.  
  1270.     this._list.selectedItem = item;
  1271.   },
  1272.  
  1273.   /**
  1274.    * Whether or not the given handler app is valid.
  1275.    *
  1276.    * @param aHandlerApp {nsIHandlerApp} the handler app in question
  1277.    *
  1278.    * @returns {boolean} whether or not it's valid
  1279.    */
  1280.   isValidHandlerApp: function(aHandlerApp) {
  1281.     if (!aHandlerApp)
  1282.       return false;
  1283.  
  1284.     if (aHandlerApp instanceof Ci.nsILocalHandlerApp)
  1285.       return this._isValidHandlerExecutable(aHandlerApp.executable);
  1286.  
  1287.     if (aHandlerApp instanceof Ci.nsIWebHandlerApp)
  1288.       return aHandlerApp.uriTemplate;
  1289.  
  1290.     if (aHandlerApp instanceof Ci.nsIWebContentHandlerInfo)
  1291.       return aHandlerApp.uri;
  1292.  
  1293.     return false;
  1294.   },
  1295.  
  1296.   _isValidHandlerExecutable: function(aExecutable) {
  1297.     return aExecutable &&
  1298.            aExecutable.exists() &&
  1299.            aExecutable.isExecutable() &&
  1300. // XXXben - we need to compare this with the running instance executable
  1301. //          just don't know how to do that via script...
  1302. // XXXmano TBD: can probably add this to nsIShellService
  1303.    aExecutable.leafName != "firefox.exe";
  1304. //@line 1367 "/e/fx19rel/WINNT_5.2_Depend/mozilla/browser/components/preferences/applications.js"
  1305.   },
  1306.  
  1307.   /**
  1308.    * Rebuild the actions menu for the selected entry.  Gets called by
  1309.    * the richlistitem constructor when an entry in the list gets selected.
  1310.    */
  1311.   rebuildActionsMenu: function() {
  1312.     var typeItem = this._list.selectedItem;
  1313.     var handlerInfo = this._handledTypes[typeItem.type];
  1314.     var menu =
  1315.       document.getAnonymousElementByAttribute(typeItem, "class", "actionsMenu");
  1316.     var menuPopup = menu.menupopup;
  1317.  
  1318.     // Clear out existing items.
  1319.     while (menuPopup.hasChildNodes())
  1320.       menuPopup.removeChild(menuPopup.lastChild);
  1321.  
  1322.     {
  1323.       var askMenuItem = document.createElement("menuitem");
  1324.       askMenuItem.setAttribute("alwaysAsk", "true");
  1325.       let label;
  1326.       if (isFeedType(handlerInfo.type))
  1327.         label = this._prefsBundle.getFormattedString("previewInApp",
  1328.                                                      [this._brandShortName]);
  1329.       else
  1330.         label = this._prefsBundle.getString("alwaysAsk");
  1331.       askMenuItem.setAttribute("label", label);
  1332.       askMenuItem.setAttribute("tooltiptext", label);
  1333.       askMenuItem.setAttribute(APP_ICON_ATTR_NAME, "ask");
  1334.       menuPopup.appendChild(askMenuItem);
  1335.     }
  1336.  
  1337.     // Create a menu item for saving to disk.
  1338.     // Note: this option isn't available to protocol types, since we don't know
  1339.     // what it means to save a URL having a certain scheme to disk, nor is it
  1340.     // available to feeds, since the feed code doesn't implement the capability.
  1341.     if ((handlerInfo.wrappedHandlerInfo instanceof Ci.nsIMIMEInfo) &&
  1342.         !isFeedType(handlerInfo.type)) {
  1343.       var saveMenuItem = document.createElement("menuitem");
  1344.       saveMenuItem.setAttribute("action", Ci.nsIHandlerInfo.saveToDisk);
  1345.       let label = this._prefsBundle.getString("saveFile");
  1346.       saveMenuItem.setAttribute("label", label);
  1347.       saveMenuItem.setAttribute("tooltiptext", label);
  1348.       saveMenuItem.setAttribute(APP_ICON_ATTR_NAME, "save");
  1349.       menuPopup.appendChild(saveMenuItem);
  1350.     }
  1351.  
  1352.     // If this is the feed type, add a Live Bookmarks item.
  1353.     if (isFeedType(handlerInfo.type)) {
  1354.       var internalMenuItem = document.createElement("menuitem");
  1355.       internalMenuItem.setAttribute("action", Ci.nsIHandlerInfo.handleInternally);
  1356.       let label = this._prefsBundle.getFormattedString("addLiveBookmarksInApp",
  1357.                                                        [this._brandShortName]);
  1358.       internalMenuItem.setAttribute("label", label);
  1359.       internalMenuItem.setAttribute("tooltiptext", label);
  1360.       internalMenuItem.setAttribute(APP_ICON_ATTR_NAME, "feed");
  1361.       menuPopup.appendChild(internalMenuItem);
  1362.     }
  1363.  
  1364.     // Add a separator to distinguish these items from the helper app items
  1365.     // that follow them.
  1366.     let menuItem = document.createElement("menuseparator");
  1367.     menuPopup.appendChild(menuItem);
  1368.  
  1369.     // Create a menu item for the OS default application, if any.
  1370.     if (handlerInfo.hasDefaultHandler) {
  1371.       var defaultMenuItem = document.createElement("menuitem");
  1372.       defaultMenuItem.setAttribute("action", Ci.nsIHandlerInfo.useSystemDefault);
  1373.       let label = this._prefsBundle.getFormattedString("useDefault",
  1374.                                                        [handlerInfo.defaultDescription]);
  1375.       defaultMenuItem.setAttribute("label", label);
  1376.       defaultMenuItem.setAttribute("tooltiptext", handlerInfo.defaultDescription);
  1377.       defaultMenuItem.setAttribute("image", this._getIconURLForSystemDefault(handlerInfo));
  1378.  
  1379.       menuPopup.appendChild(defaultMenuItem);
  1380.     }
  1381.  
  1382.     // Create menu items for possible handlers.
  1383.     let preferredApp = handlerInfo.preferredApplicationHandler;
  1384.     let possibleApps = handlerInfo.possibleApplicationHandlers.enumerate();
  1385.     var possibleAppMenuItems = [];
  1386.     while (possibleApps.hasMoreElements()) {
  1387.       let possibleApp = possibleApps.getNext();
  1388.       if (!this.isValidHandlerApp(possibleApp))
  1389.         continue;
  1390.  
  1391.       let menuItem = document.createElement("menuitem");
  1392.       menuItem.setAttribute("action", Ci.nsIHandlerInfo.useHelperApp);
  1393.       let label;
  1394.       if (possibleApp instanceof Ci.nsILocalHandlerApp)
  1395.         label = getDisplayNameForFile(possibleApp.executable);
  1396.       else
  1397.         label = possibleApp.name;
  1398.       label = this._prefsBundle.getFormattedString("useApp", [label]);
  1399.       menuItem.setAttribute("label", label);
  1400.       menuItem.setAttribute("tooltiptext", label);
  1401.       menuItem.setAttribute("image", this._getIconURLForHandlerApp(possibleApp));
  1402.  
  1403.       // Attach the handler app object to the menu item so we can use it
  1404.       // to make changes to the datastore when the user selects the item.
  1405.       menuItem.handlerApp = possibleApp;
  1406.  
  1407.       menuPopup.appendChild(menuItem);
  1408.       possibleAppMenuItems.push(menuItem);
  1409.     }
  1410.  
  1411.     // Create a menu item for the plugin.
  1412.     if (handlerInfo.plugin) {
  1413.       var pluginMenuItem = document.createElement("menuitem");
  1414.       pluginMenuItem.setAttribute("action", kActionUsePlugin);
  1415.       let label = this._prefsBundle.getFormattedString("usePluginIn",
  1416.                                                        [handlerInfo.plugin.name,
  1417.                                                         this._brandShortName]);
  1418.       pluginMenuItem.setAttribute("label", label);
  1419.       pluginMenuItem.setAttribute("tooltiptext", label);
  1420.       pluginMenuItem.setAttribute(APP_ICON_ATTR_NAME, "plugin");
  1421.       menuPopup.appendChild(pluginMenuItem);
  1422.     }
  1423.  
  1424.     // Create a menu item for selecting a local application.
  1425. //@line 1488 "/e/fx19rel/WINNT_5.2_Depend/mozilla/browser/components/preferences/applications.js"
  1426.     // On Windows, selecting an application to open another application
  1427.     // would be meaningless so we special case executables.
  1428.     var executableType = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService)
  1429.                                                   .getTypeFromExtension("exe");
  1430.     if (handlerInfo.type != executableType)
  1431. //@line 1494 "/e/fx19rel/WINNT_5.2_Depend/mozilla/browser/components/preferences/applications.js"
  1432.     {
  1433.       let menuItem = document.createElement("menuitem");
  1434.       menuItem.setAttribute("oncommand", "gApplicationsPane.chooseApp(event)");
  1435.       let label = this._prefsBundle.getString("useOtherApp");
  1436.       menuItem.setAttribute("label", label);
  1437.       menuItem.setAttribute("tooltiptext", label);
  1438.       menuPopup.appendChild(menuItem);
  1439.     }
  1440.  
  1441.     // Create a menu item for managing applications.
  1442.     if (possibleAppMenuItems.length) {
  1443.       let menuItem = document.createElement("menuseparator");
  1444.       menuPopup.appendChild(menuItem);
  1445.       menuItem = document.createElement("menuitem");
  1446.       menuItem.setAttribute("oncommand", "gApplicationsPane.manageApp(event)");
  1447.       menuItem.setAttribute("label", this._prefsBundle.getString("manageApp"));
  1448.       menuPopup.appendChild(menuItem);
  1449.     }
  1450.  
  1451.     // Select the item corresponding to the preferred action.  If the always
  1452.     // ask flag is set, it overrides the preferred action.  Otherwise we pick
  1453.     // the item identified by the preferred action (when the preferred action
  1454.     // is to use a helper app, we have to pick the specific helper app item).
  1455.     if (handlerInfo.alwaysAskBeforeHandling)
  1456.       menu.selectedItem = askMenuItem;
  1457.     else switch (handlerInfo.preferredAction) {
  1458.       case Ci.nsIHandlerInfo.handleInternally:
  1459.         menu.selectedItem = internalMenuItem;
  1460.         break;
  1461.       case Ci.nsIHandlerInfo.useSystemDefault:
  1462.         menu.selectedItem = defaultMenuItem;
  1463.         break;
  1464.       case Ci.nsIHandlerInfo.useHelperApp:
  1465.         if (preferredApp)
  1466.           menu.selectedItem = 
  1467.             possibleAppMenuItems.filter(function(v) v.handlerApp.equals(preferredApp))[0];
  1468.         break;
  1469.       case kActionUsePlugin:
  1470.         menu.selectedItem = pluginMenuItem;
  1471.         break;
  1472.       case Ci.nsIHandlerInfo.saveToDisk:
  1473.         menu.selectedItem = saveMenuItem;
  1474.         break;
  1475.     }
  1476.   },
  1477.  
  1478.  
  1479.   //**************************************************************************//
  1480.   // Sorting & Filtering
  1481.  
  1482.   _sortColumn: null,
  1483.  
  1484.   /**
  1485.    * Sort the list when the user clicks on a column header.
  1486.    */
  1487.   sort: function (event) {
  1488.     var column = event.target;
  1489.  
  1490.     // If the user clicked on a new sort column, remove the direction indicator
  1491.     // from the old column.
  1492.     if (this._sortColumn && this._sortColumn != column)
  1493.       this._sortColumn.removeAttribute("sortDirection");
  1494.  
  1495.     this._sortColumn = column;
  1496.  
  1497.     // Set (or switch) the sort direction indicator.
  1498.     if (column.getAttribute("sortDirection") == "ascending")
  1499.       column.setAttribute("sortDirection", "descending");
  1500.     else
  1501.       column.setAttribute("sortDirection", "ascending");
  1502.  
  1503.     this._sortVisibleTypes();
  1504.     this._rebuildView();
  1505.   },
  1506.  
  1507.   /**
  1508.    * Sort the list of visible types by the current sort column/direction.
  1509.    */
  1510.   _sortVisibleTypes: function() {
  1511.     if (!this._sortColumn)
  1512.       return;
  1513.  
  1514.     var t = this;
  1515.  
  1516.     function sortByType(a, b) {
  1517.       return t._describeType(a).toLowerCase().
  1518.              localeCompare(t._describeType(b).toLowerCase());
  1519.     }
  1520.  
  1521.     function sortByAction(a, b) {
  1522.       return t._describePreferredAction(a).toLowerCase().
  1523.              localeCompare(t._describePreferredAction(b).toLowerCase());
  1524.     }
  1525.  
  1526.     switch (this._sortColumn.getAttribute("value")) {
  1527.       case "type":
  1528.         this._visibleTypes.sort(sortByType);
  1529.         break;
  1530.       case "action":
  1531.         this._visibleTypes.sort(sortByAction);
  1532.         break;
  1533.     }
  1534.  
  1535.     if (this._sortColumn.getAttribute("sortDirection") == "descending")
  1536.       this._visibleTypes.reverse();
  1537.   },
  1538.  
  1539.   /**
  1540.    * Filter the list when the user enters a filter term into the filter field.
  1541.    */
  1542.   filter: function() {
  1543.     if (this._filter.value == "") {
  1544.       this.clearFilter();
  1545.       return;
  1546.     }
  1547.  
  1548.     this._rebuildView();
  1549.  
  1550.     document.getElementById("clearFilter").disabled = false;
  1551.   },
  1552.  
  1553.   _filterTimeout: null,
  1554.  
  1555.   onFilterInput: function() {
  1556.     if (this._filterTimeout)
  1557.       clearTimeout(this._filterTimeout);
  1558.    
  1559.     this._filterTimeout = setTimeout("gApplicationsPane.filter()", 500);
  1560.   },
  1561.  
  1562.   onFilterKeyPress: function(aEvent) {
  1563.     if (aEvent.keyCode == KeyEvent.DOM_VK_ESCAPE)
  1564.       this.clearFilter();
  1565.   },
  1566.   
  1567.   clearFilter: function() {
  1568.     this._filter.value = "";
  1569.     this._rebuildView();
  1570.  
  1571.     this._filter.focus();
  1572.     document.getElementById("clearFilter").disabled = true;
  1573.   },
  1574.  
  1575.   focusFilterBox: function() {
  1576.     this._filter.focus();
  1577.     this._filter.select();
  1578.   },
  1579.  
  1580.  
  1581.   //**************************************************************************//
  1582.   // Changes
  1583.  
  1584.   onSelectAction: function(aActionItem) {
  1585.     this._storingAction = true;
  1586.  
  1587.     try {
  1588.       this._storeAction(aActionItem);
  1589.     }
  1590.     finally {
  1591.       this._storingAction = false;
  1592.     }
  1593.   },
  1594.  
  1595.   _storeAction: function(aActionItem) {
  1596.     var typeItem = this._list.selectedItem;
  1597.     var handlerInfo = this._handledTypes[typeItem.type];
  1598.  
  1599.     if (aActionItem.hasAttribute("alwaysAsk")) {
  1600.       handlerInfo.alwaysAskBeforeHandling = true;
  1601.     }
  1602.     else if (aActionItem.hasAttribute("action")) {
  1603.       let action = parseInt(aActionItem.getAttribute("action"));
  1604.  
  1605.       // Set the plugin state if we're enabling or disabling a plugin.
  1606.       if (action == kActionUsePlugin)
  1607.         handlerInfo.enablePluginType();
  1608.       else if (handlerInfo.plugin && !handlerInfo.isDisabledPluginType)
  1609.         handlerInfo.disablePluginType();
  1610.  
  1611.       // Set the preferred application handler.
  1612.       // We leave the existing preferred app in the list when we set
  1613.       // the preferred action to something other than useHelperApp so that
  1614.       // legacy datastores that don't have the preferred app in the list
  1615.       // of possible apps still include the preferred app in the list of apps
  1616.       // the user can choose to handle the type.
  1617.       if (action == Ci.nsIHandlerInfo.useHelperApp)
  1618.         handlerInfo.preferredApplicationHandler = aActionItem.handlerApp;
  1619.  
  1620.       // Set the "always ask" flag.
  1621.       handlerInfo.alwaysAskBeforeHandling = false;
  1622.  
  1623.       // Set the preferred action.
  1624.       handlerInfo.preferredAction = action;
  1625.     }
  1626.  
  1627.     handlerInfo.store();
  1628.  
  1629.     // Make sure the handler info object is flagged to indicate that there is
  1630.     // now some user configuration for the type.
  1631.     handlerInfo.handledOnlyByPlugin = false;
  1632.  
  1633.     // Update the action label and image to reflect the new preferred action.
  1634.     typeItem.setAttribute("actionDescription",
  1635.                           this._describePreferredAction(handlerInfo));
  1636.     if (!this._setIconClassForPreferredAction(handlerInfo, typeItem)) {
  1637.       typeItem.setAttribute("actionIcon",
  1638.                             this._getIconURLForPreferredAction(handlerInfo));
  1639.     }
  1640.   },
  1641.  
  1642.   manageApp: function(aEvent) {
  1643.     // Don't let the normal "on select action" handler get this event,
  1644.     // as we handle it specially ourselves.
  1645.     aEvent.stopPropagation();
  1646.  
  1647.     var typeItem = this._list.selectedItem;
  1648.     var handlerInfo = this._handledTypes[typeItem.type];
  1649.  
  1650.     document.documentElement.openSubDialog("chrome://browser/content/preferences/applicationManager.xul",
  1651.                                            "", handlerInfo);
  1652.  
  1653.     // Rebuild the actions menu so that we revert to the previous selection,
  1654.     // or "Always ask" if the previous default application has been removed
  1655.     this.rebuildActionsMenu();
  1656.  
  1657.     // update the richlistitem too. Will be visible when selecting another row
  1658.     typeItem.setAttribute("actionDescription",
  1659.                           this._describePreferredAction(handlerInfo));
  1660.     if (!this._setIconClassForPreferredAction(handlerInfo, typeItem)) {
  1661.       typeItem.setAttribute("actionIcon",
  1662.                             this._getIconURLForPreferredAction(handlerInfo));
  1663.     }
  1664.   },
  1665.  
  1666.   chooseApp: function(aEvent) {
  1667.     // Don't let the normal "on select action" handler get this event,
  1668.     // as we handle it specially ourselves.
  1669.     aEvent.stopPropagation();
  1670.  
  1671.     var handlerApp;
  1672.  
  1673. //@line 1736 "/e/fx19rel/WINNT_5.2_Depend/mozilla/browser/components/preferences/applications.js"
  1674.     var params = {};
  1675.     var handlerInfo = this._handledTypes[this._list.selectedItem.type];
  1676.  
  1677.     if (isFeedType(handlerInfo.type)) {
  1678.       // MIME info will be null, create a temp object.
  1679.       params.mimeInfo = this._mimeSvc.getFromTypeAndExtension(handlerInfo.type, 
  1680.                                                  handlerInfo.primaryExtension);
  1681.     } else {
  1682.       params.mimeInfo = handlerInfo.wrappedHandlerInfo;
  1683.     }
  1684.  
  1685.     params.title         = this._prefsBundle.getString("fpTitleChooseApp");
  1686.     params.description   = handlerInfo.description;
  1687.     params.filename      = null;
  1688.     params.handlerApp    = null;
  1689.  
  1690.     window.openDialog("chrome://global/content/appPicker.xul", null,
  1691.                       "chrome,modal,centerscreen,titlebar,dialog=yes",
  1692.                       params);
  1693.  
  1694.     if (params.handlerApp && 
  1695.         params.handlerApp.executable && 
  1696.         params.handlerApp.executable.isFile()) {
  1697.       handlerApp = params.handlerApp;
  1698.  
  1699.       // Add the app to the type's list of possible handlers.
  1700.       handlerInfo.addPossibleApplicationHandler(handlerApp);
  1701.     }
  1702. //@line 1784 "/e/fx19rel/WINNT_5.2_Depend/mozilla/browser/components/preferences/applications.js"
  1703.  
  1704.     // Rebuild the actions menu whether the user picked an app or canceled.
  1705.     // If they picked an app, we want to add the app to the menu and select it.
  1706.     // If they canceled, we want to go back to their previous selection.
  1707.     this.rebuildActionsMenu();
  1708.  
  1709.     // If the user picked a new app from the menu, select it.
  1710.     if (handlerApp) {
  1711.       let typeItem = this._list.selectedItem;
  1712.       let actionsMenu =
  1713.         document.getAnonymousElementByAttribute(typeItem, "class", "actionsMenu");
  1714.       let menuItems = actionsMenu.menupopup.childNodes;
  1715.       for (let i = 0; i < menuItems.length; i++) {
  1716.         let menuItem = menuItems[i];
  1717.         if (menuItem.handlerApp && menuItem.handlerApp.equals(handlerApp)) {
  1718.           actionsMenu.selectedIndex = i;
  1719.           this.onSelectAction(menuItem);
  1720.           break;
  1721.         }
  1722.       }
  1723.     }
  1724.   },
  1725.  
  1726.   // Mark which item in the list was last selected so we can reselect it
  1727.   // when we rebuild the list or when the user returns to the prefpane.
  1728.   onSelectionChanged: function() {
  1729.     if (this._list.selectedItem)
  1730.       this._list.setAttribute("lastSelectedType",
  1731.                               this._list.selectedItem.getAttribute("type"));
  1732.   },
  1733.  
  1734.   _setIconClassForPreferredAction: function(aHandlerInfo, aElement) {
  1735.     // If this returns true, the attribute that CSS sniffs for was set to something
  1736.     // so you shouldn't manually set an icon URI.
  1737.     // This removes the existing actionIcon attribute if any, even if returning false.
  1738.     aElement.removeAttribute("actionIcon");
  1739.  
  1740.     if (aHandlerInfo.alwaysAskBeforeHandling) {
  1741.       aElement.setAttribute(APP_ICON_ATTR_NAME, "ask");
  1742.       return true;
  1743.     }
  1744.  
  1745.     switch (aHandlerInfo.preferredAction) {
  1746.       case Ci.nsIHandlerInfo.saveToDisk:
  1747.         aElement.setAttribute(APP_ICON_ATTR_NAME, "save");
  1748.         return true;
  1749.  
  1750.       case Ci.nsIHandlerInfo.handleInternally:
  1751.         if (isFeedType(aHandlerInfo.type)) {
  1752.           aElement.setAttribute(APP_ICON_ATTR_NAME, "feed");
  1753.           return true;
  1754.         }
  1755.         break;
  1756.  
  1757.       case kActionUsePlugin:
  1758.         aElement.setAttribute(APP_ICON_ATTR_NAME, "plugin");
  1759.         return true;
  1760.     }
  1761.     aElement.removeAttribute(APP_ICON_ATTR_NAME);
  1762.     return false;
  1763.   },
  1764.  
  1765.   _getIconURLForPreferredAction: function(aHandlerInfo) {
  1766.     switch (aHandlerInfo.preferredAction) {
  1767.       case Ci.nsIHandlerInfo.useSystemDefault:
  1768.         return this._getIconURLForSystemDefault(aHandlerInfo);
  1769.  
  1770.       case Ci.nsIHandlerInfo.useHelperApp:
  1771.         let (preferredApp = aHandlerInfo.preferredApplicationHandler) {
  1772.           if (this.isValidHandlerApp(preferredApp))
  1773.             return this._getIconURLForHandlerApp(preferredApp);
  1774.         }
  1775.         break;
  1776.  
  1777.       // This should never happen, but if preferredAction is set to some weird
  1778.       // value, then fall back to the generic application icon.
  1779.       default:
  1780.         return ICON_URL_APP;
  1781.     }
  1782.   },
  1783.  
  1784.   _getIconURLForHandlerApp: function(aHandlerApp) {
  1785.     if (aHandlerApp instanceof Ci.nsILocalHandlerApp)
  1786.       return this._getIconURLForFile(aHandlerApp.executable);
  1787.  
  1788.     if (aHandlerApp instanceof Ci.nsIWebHandlerApp)
  1789.       return this._getIconURLForWebApp(aHandlerApp.uriTemplate);
  1790.  
  1791.     if (aHandlerApp instanceof Ci.nsIWebContentHandlerInfo)
  1792.       return this._getIconURLForWebApp(aHandlerApp.uri)
  1793.  
  1794.     // We know nothing about other kinds of handler apps.
  1795.     return "";
  1796.   },
  1797.  
  1798.   _getIconURLForFile: function(aFile) {
  1799.     var fph = this._ioSvc.getProtocolHandler("file").
  1800.               QueryInterface(Ci.nsIFileProtocolHandler);
  1801.     var urlSpec = fph.getURLSpecFromFile(aFile);
  1802.  
  1803.     return "moz-icon://" + urlSpec + "?size=16";
  1804.   },
  1805.  
  1806.   _getIconURLForWebApp: function(aWebAppURITemplate) {
  1807.     var uri = this._ioSvc.newURI(aWebAppURITemplate, null, null);
  1808.  
  1809.     // Unfortunately we can't use the favicon service to get the favicon,
  1810.     // because the service looks in the annotations table for a record with
  1811.     // the exact URL we give it, and users won't have such records for URLs
  1812.     // they don't visit, and users won't visit the web app's URL template,
  1813.     // they'll only visit URLs derived from that template (i.e. with %s
  1814.     // in the template replaced by the URL of the content being handled).
  1815.  
  1816.     if (/^https?/.test(uri.scheme))
  1817.       return uri.prePath + "/favicon.ico";
  1818.  
  1819.     return "";
  1820.   },
  1821.  
  1822.   _getIconURLForSystemDefault: function(aHandlerInfo) {
  1823.     // Handler info objects for MIME types on some OSes implement a property bag
  1824.     // interface from which we can get an icon for the default app, so if we're
  1825.     // dealing with a MIME type on one of those OSes, then try to get the icon.
  1826.     if ("wrappedHandlerInfo" in aHandlerInfo) {
  1827.       let wrappedHandlerInfo = aHandlerInfo.wrappedHandlerInfo;
  1828.  
  1829.       if (wrappedHandlerInfo instanceof Ci.nsIMIMEInfo &&
  1830.           wrappedHandlerInfo instanceof Ci.nsIPropertyBag) {
  1831.         try {
  1832.           let url = wrappedHandlerInfo.getProperty("defaultApplicationIconURL");
  1833.           if (url)
  1834.             return url + "?size=16";
  1835.         }
  1836.         catch(ex) {}
  1837.       }
  1838.     }
  1839.  
  1840.     // If this isn't a MIME type object on an OS that supports retrieving
  1841.     // the icon, or if we couldn't retrieve the icon for some other reason,
  1842.     // then use a generic icon.
  1843.     return ICON_URL_APP;
  1844.   }
  1845.  
  1846. };
  1847.